<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Menu
 *
 * @author aneto
 */
class NavigationAdminMenuWithPermissions extends NavigationDefaultMenu{
    //put your code here


	protected function initElements(){

		$user = sfContext::getInstance()->getUser();
	
		if(!$user->isAuthenticated()){
			throw new Exception('user is not authenticated');
		}
		
		$q = Doctrine_Query::create()
			->from('Structure s')
			->select('s.*')
			->innerJoin('s.PublicUserGroups pug')
			->where('s.isHidden = ? and pug.group_id = ?', array(false, $user->getObject()->getPublicUserGroup()->getId()))
			->orderBy('s.lft')
			->setHydrationMode(Doctrine::HYDRATE_ARRAY);


		
		$result = $q->execute();
		$result[0]['__children'] = $result[0]['Structure'];

		foreach($result as $index => $elem){ // there is always Structure nodes on the top
			$this->elements[$index] = MenuElement::getInstance($elem, MenuElement::STRUCTURE_NODE, $this, null);
		}



	}
}